
namespace GSN.Mail
{
    class MailManagerFactory
    {
        public static IMailManager getMailManager()
        {
            string mailType = GSNConfig.getConfigItem(GSNConfig.GSN_CONFIG_MAIL_TYPE);
            string username = GSNConfig.getConfigItem(GSNConfig.GSN_CONFIG_MAIL_USERNAME);
            string password = GSNConfig.getConfigPasswordItem(GSNConfig.GSN_CONFIG_MAIL_PASSWORD);

            IMailManager mm = null;

            switch (mailType.ToLower())
            {
                case "gmail":
                    mm = new GmailManager(username, password);
                    break;
                case "pop3":
                    mm = new POP3Manager(username, password,
                        GSNConfig.getConfigItem(GSNConfig.GSN_CONFIG_MAIL_SERVER),
                        GSNConfig.getConfigItemInt(GSNConfig.GSN_CONFIG_MAIL_PORT));
                    break;
                case "imap":
                    mm = new IMAPManager(username, password,
                        GSNConfig.getConfigItem(GSNConfig.GSN_CONFIG_MAIL_SERVER),
                        GSNConfig.getConfigItemInt(GSNConfig.GSN_CONFIG_MAIL_PORT));
                    break;
                default:
                    throw new System.Exception("Mail Type not supported! Check configuration.");
                    //break;
            }

            return mm;
        }
    }
}
